<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/publicPage.jsp"%>
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>信息权限管理</title>
    <%@ include file="/publicIcon.jsp"%>
    <%@ include file="/publicLigerUI.jsp"%>
    <%@ include file="/publicGridJS.jsp"%>
    <script type="text/javascript">
        function itemclick(item){
            alert(item.text);
        }
        var iHeight = document.documentElement.clientHeight||document.body.clientHeight;
        var iWidth = document.documentElement.clientWidth||document.body.clientWidth;
        var gridManager,win1 ;
        $(function (){
            //布局
            $("#layout1").ligerLayout({ leftWidth: 190, height: '100%',heightDiff:-34,space:4 });
            gridManager =
                $("#maingrid").ligerGrid({
                    height:'100%',
                    checkbox: true,
                    width:'100%',
                    columns: [
                        { display: '编号', name: 'valveTableId',hide:true,width:'%'},
                        { display: '消息名',width: '50%', name: 'valveName' },
                        { display: '状态', name: 'enabled',width: '50%',
                            render:function(data){
                                if(data.enabled==0){
                                    return "禁用";
                                }
                                if(data.enabled==1){
                                    return "启用";
                                }
                            }
                        },
                        { display: '是否启用', name: 'enabled',width: '50%',
                            render:function(data){
                                if(data.enabled==0){
                                    return "<a href='javascript:void(0);' onclick=updateStatus('" +data.valveTableId +"','"+data.enabled+"') ><font color='red' >启用</font></a>";
                                }
                                if(data.enabled==1){
                                    return "<a href='javascript:void(0);' onclick=updateStatus('" +data.valveTableId +"','"+data.enabled+"') ><font color='green' >禁用</font></a>";
                                }
                            }
                        }
                    ],url:'/rest/valve/List',  pageSize:30 ,rownumbers:true,
                    enabledEdit: true,
                    onDblClickRow : function (data, rowindex, rowobj){
                        f_DblClickRow(data);
                    },
                    toolbar: { items: [
                            { text: '添加', click: function(item){
                                    f_Create();
                                }, icon: 'add' },
                            { line: true },
                            { text: '修改', click: function(item){
                                    f_Update();
                                }, icon: 'modify' },
                            { line: true },
                            { text: '删除', click: function(item){
                                    f_Delete();
                                }, icon:'delete'},
                            { text: '刷新', click: function(item){
                                    loadData();
                                }, icon:'refresh'}
                        ]
                    }
                });
            $("#pageloading").hide();
        });

        //测试获取隐藏colunmns的属性
        <%--function testHide(){--%>
        <%--var grid = jQuery("#maingrid").ligerGrid();--%>
        <%--$.ajax({--%>
        <%--type:"POST",--%>
        <%--url:'${pageContext.request.contextPath}/rest/style/createStyle',--%>
        <%--data: $('#form1').serialize(),--%>
        <%--async: false,--%>
        <%--success: function (data) {--%>
        <%--/* window.parent.okdialog();--%>
        <%--window.parent.loadData();--%>
        <%--window.parent.closeDialog(); */--%>
        <%--},--%>
        <%--error: function (request) {--%>
        <%--/* $.ligerDialog.error('添加失败！', function ()--%>
        <%--{--%>
        <%--window.parent.loadData();--%>
        <%--window.parent.closeDialog();--%>
        <%--}) */--%>
        <%--}--%>
        <%--});--%>

        <%--for (i = 2; i < grid.columns.length; i++) {--%>
        <%--if (grid.columns[i]._hide != true && grid.columns[i]._hide != "true") {--%>
        <%--/* alert(grid.columns[i].display+"+======"+grid.columns[i]._hide); */--%>
        <%--}else{--%>
        <%--/* alert(grid.columns[i].display+"+======"+grid.columns[i]._hide); */--%>
        <%--}--%>
        <%--}--%>
        <%--}--%>


        function f_heightChanged(options){
            if (tab)
                tab.addHeight(options.diff);
            if (accordion && options.middleHeight - 24 > 0)
                accordion.setHeight(options.middleHeight - 24);
        }

        //添加
        function f_Create(){
            win1 = $.ligerDialog.open({
                height:250, url: '/rest/valve/doValveAdd',
                title:"添加信息",
                width: 550,
                showMax: true,
                showToggle: true,
                showMin: false,
                isResize: true,
                slide: false
            });
        }

        //修改
        function f_Update(){
            var selRow = gridManager.getSelecteds();//返回选中多行
            if(selRow.length>=2){
                $.ligerDialog.warn('您已选中多行数据,请确定需要修改的一行记录!');
                return false;
            }
            var selected = gridManager.getSelected();
            if (!selected) { $.ligerDialog.warn('请选中一行!'); return; }
            win1 = $.ligerDialog.open({
                height: 250,
                url: '/rest/valve/valveById?valveTableId='+selected.valveTableId,
                title:"修改信息",
                width: 550,
                showMax: true,
                showToggle: true,
                showMin: false,
                isResize: true,
                slide: false
            });
            //win1.max();
        }
        //双击修改
        function f_DblClickRow(data){
            win1 = $.ligerDialog.open({
                height: 250,
                url: '/rest/valve/valveById?valveTableId='+data.valveTableId,
                title:"修改信息",
                width: 550,
                showMax: true,
                showToggle: true,
                showMin: false,
                isResize: true,
                slide: false
            });
            //win1.max();
        }
        //删除
        function f_Delete(){
            var selected = gridManager.getSelected();
            if (!selected) { $.ligerDialog.warn('请选中一行!'); return; }
            $.ligerDialog.confirm('你确定要删除吗?', function (yes){
                var selRow = gridManager.getSelecteds();//返回选中多行
                var valveTableId="";
                for(var i=0;i<selRow.length;i++){

                    valveTableId+=selRow[i].valveTableId+",";
                }
                if(yes){
                    $.ajax({ url:"/rest/valve/valveDel?valveTableId=" +valveTableId,
                        type: "post",
                        contentType:"charset=utf-8",
                        success: function(result){
                            gridManager.loadData();
                            gridManager.closeDialog();
                        },
                        error: function (request) {
                            window.parent.nodialog();
                        }
                    });
                }
            });

        }

        //grid刷新
        function loadData(){
            gridManager.loadData();
        }

        //关闭子窗口
        function closeDialog(){
            if(win1){win1.close();}
        }

        //成功操作
        function okdialog(){
            $.ligerDialog.success('操作成功!');
        }

        //失败操作
        function nodialog(){
            $.ligerDialog.error('操作失败!');
        }
        //关闭子窗口from
        function closeFrom(){
            win1.close();
        }
        //清空输入框
        function resetAll(){
            $('input:button').click(function(){
                $('.input').val("");
            });
        }
        //按条件查询
        $(function(){
            $("#Button1").ligerButton({
                click: function () {
                    //重置查询页数，从第一页开始
                    gridManager.set({ page: 1, newPage: 1 });
                    //设置Ajax参数
                    gridManager.setParm("valveName", $("#txtKey").val());
                    //重新请求
                    gridManager.loadData(gridManager.url);
                }
            });


            //回车键执行查询
            $(":text").focus(function(){
                document.onkeydown=function(event){
                    if(event.keyCode == "13"){//绑定回车键
                        $("#Button1").click(); //自动触发查询按钮单击事件
                    }
                };
            });

        });


        /*是否开启*/
        function updateStatus(id,status){
            var flag;
            if(status==0){
                flag = 1;
            }else{
                flag = 0;
            }

            var params = {
                valveTableId    : id,
                enabled : flag
            }

            $.ajax({
                data: params,
                url: "/rest/valve/valveUpdate",
                type: "post",
                async:false,//同步请求
                dataType:"text/html;charset=utf-8"
            });

            gridManager.loadData();

        }
    </script>
</head>
<body>
<div id="layout1">
    <div  title="表表">
        <ul>
            <li style="margin:10px">
                信息名：
                <input class="input" name="txtKey" type="text" id="txtKey" ltype="text" />&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="submit"  value="查询" id="Button1" class="l-button l-button-submit" />
            </li>
        </ul>
        <div id="maingrid"></div>
    </div>
    <div style="display: none;">
    </div>
</div>
</body>
</html>
